using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace proyecto35.admin.colores_dir
{
    public partial class main_colores2 : System.Web.UI.Page
    {
        protected static int idportal;
        protected void Page_Load(object sender, EventArgs e)
        {

            idportal = sf.entero(HttpContext.Current.Session["admin"]);


            if (!Page.IsPostBack)
            {
                if (portales.exists(idportal))
                    lblportal.Text = portales.getportales(idportal).nombre;
                cargar();

            }

            PanelAviso.Visible = false;
            if (!Page.IsPostBack)
            {
                // Borrar
                if (Request["idb"] != null)
                {
                    colores.Delete(sf.entero(Request["idb"]));
                    Response.Redirect("./listado_colores.aspx");
                }
                // Editar
                if (Request["id"] != null)
                {
                    colores res = new colores(sf.entero(Request["id"]));


                    txtnombre.Text = res.nombre;



                    colorpickerField1.Text = res.hexadecimal;
                }
                else
                {
                    butModificar.Text = "Insertar";
                }
            }
        }
        protected void butModificar_Click(object sender, EventArgs e)
        {
            lblinfo.Text = "";
            // modificar
            if (Request["id"] != null)
            {
                colores res = new colores(sf.entero(Request["id"]));






                res.nombre = sf.SafeSql(sf.cadena(txtnombre.Text));



                res.hexadecimal = sf.SafeSql(sf.cadena(colorpickerField1.Text));
                if (lblinfo.Text == "")
                {
                    res.Update();
                    res = null;
                    mensaje("Modificado con exito", true);
                }
            }
            // insertar...
            else
            {
                colores res = new colores();




                res.nombre = sf.SafeSql(sf.cadena(txtnombre.Text));


                res.hexadecimal = sf.SafeSql(sf.cadena(colorpickerField1.Text));
                if (lblinfo.Text == "")
                {
                    colores.Insert(res);
                    res = null;
                    mensaje("Insertado con exito", true);
                }


            }
        }


        private void mensaje(string p, bool ok)
        {
            if (!ok)
                PanelAviso.CssClass = "error";
            else
                PanelAviso.CssClass = "aviso";
            lblinfo.Text = p;
            lblinfo.Visible = true;
            PanelAviso.Visible = true;
        }
        protected void butCancelar_Click(object sender, EventArgs e)
        {
        }




        // funciones extra para campos extra







        #region["comun"]
        private void cargar()
        {
            if (HttpContext.Current.Session["versionadmin"] == "contraste")
            {
                btnContraste.Text = "Versi&oacute;n standard";
                btnTexto.Text = "Versi&oacute;n texto";
            }
            if (HttpContext.Current.Session["versionadmin"] == "texto")
            {
                btnContraste.Text = "Versi&oacute;n alto contraste";
                btnTexto.Text = "Versi&oacute;n standard";
            }
        }
        protected void btnNormal_Click(object sender, EventArgs e)
        {
            HttpContext.Current.Session["tamanio"] = null;
            Response.Redirect(HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"]);
        }


        protected void btnMediano_Click(object sender, EventArgs e)
        {
            HttpContext.Current.Session["tamanio"] = "med";
            Response.Redirect(HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"]);
        }

        protected void btnGrande_Click(object sender, EventArgs e)
        {
            HttpContext.Current.Session["tamanio"] = "xl";
            Response.Redirect(HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"]);

        }
        protected void btnTexto_Click(object sender, EventArgs e)
        {
            if (HttpContext.Current.Session["versionadmin"] == "contraste" | HttpContext.Current.Session["versionadmin"] == null)
            {
                HttpContext.Current.Session["versionadmin"] = "texto";
                Response.Redirect(HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"]);
            }
            else
            {
                HttpContext.Current.Session["versionadmin"] = null;
                Response.Redirect(HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"]);
            }
        }

        protected void btnContraste_Click(object sender, EventArgs e)
        {
            if (HttpContext.Current.Session["versionadmin"] == "texto" | HttpContext.Current.Session["versionadmin"] == null)
            {
                HttpContext.Current.Session["versionadmin"] = "admcontraste";
                Response.Redirect(HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"]);
            }
            else
            {
                HttpContext.Current.Session["versionadmin"] = null;
                Response.Redirect(HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"]);
            }

        }

        protected void btnCerrar_Click(object sender, EventArgs e)
        {
            HttpContext.Current.Session["admin"] = null;
            Response.Redirect("../../portal/portada_dir/main_portada.aspx");
        }

        protected void btnAccesibilidad_Click(object sender, EventArgs e)
        {
            Response.Redirect("../miscelanea/accesibilidad.aspx");
        }
        #endregion


    }
}
